﻿FlyTalk.views.ColumnView = Ext.extend(Ext.Panel, {

	//scroll: true,
	title: 'column',
	layout: 'vbox',
	scroll: true,
	//fullscreen: true,
	
    initComponent: function (options) { 	
		// list
		this.MixedStore = new Ext.data.JsonStore({
			model : 'MixedPostModel',
		});
		
		this.tweetList = new Ext.List({
			//fullscreen: true,
		
			cls: 'feeds',
			emptyText: '<div style="margin:5px;">No tweets cached.</div>',
			itemTpl : [ 
                   '<div id="touchpoint_container_{type}_{answered}">',
                        '<tpl for=".">',
                            '<div class="touchpoint_data">',
                            '<div class="touchpoint_icon">',
                                '<img width="44" height="44" src="{image_url}"/>',
                            '</div>',
                            
							'<div class="touchpoint_content_{type}">',
                                '<h3 class="touchpoint">{from_user} <!--<span class="type">{type}</span>--></h3>',
                                '<p>{text}</p>',
                            '</div>',
                            '</div>',
                            '<div class="plus_{answered}" style="float:right" ><img src="images/post_plus.png" width="44" height="44"></div>',
                            '<div class="clear"></div>',
							'<div class="tweet-details">{date}, <!--{followed}--> {up} <img src="images/thumbsUP_postscopy.png" width="10px" /> / {down} <img src="images/thumbsDown_postscopy.png" width="10px" /> <img src="{tp}" width="10px" /> translated from Portuguese</div>',
                            '</div>',
                        '</tpl>',
                    '</div>'
			],
			grouped : false,
			indexBar: false,
			width: 320,
			flex:1,
		//	onItemDisclosure: true,
			store: this.MixedStore,
			
			
			listeners:{
				itemTap: function(dv, index, tweet, e){
					if(e.getTarget('.touchpoint_icon')){
						//alert(FlyTalk.views.ColumnView.MixedStore.getAt(index).data.from_user);
						if(FlyTalk.views.ColumnView.MixedStore.getAt(index).data.from_user == "JoaoDias"){		
							FlyTalk.views.mainView.setActiveItem(FlyTalk.views.PublicProf);
						}		
					}
					else if(e.getTarget('.plus_') || e.getTarget('.plus_yes')){
						FlyTalk.views.ColumnView.onMenu(index);
						
					}	
				},
			},
		});
	
		this.items = [
		             {
		            	    xtype: 'selectfield',
		            	    name: 'sortby',
		            	    id: 'sortposts',
		            	    options: [
		            	        {text: 'People on my flight', value: 'getFlightPost'},
		            	    	{text: 'People in my terminal',  value: 'getTerminalPost'},	
		            	    	{text: 'People who speak my language', value: 'getLangPost'},
		            	        {text: 'Official notifications',  value: 'getOfficialPost'},
		            	    	{text: 'People from my hometown',  value: 'getHomePost'},
		            	    	{text: 'People close to my age',  value: 'getAgePost'},
		            	      	{text: 'People 100 feet from me',  value: 'getClosePost'},
		            	    ],
		            	    width: 320,
		            	    height: 44,
		            	    listeners:{
		        				change: function(select, opt){
		        					//alert(opt);
		        					Ext.dispatch({
		        		                controller: FlyTalk.controllers.dbController,
		        		                action: 'getSpecificPost',
		        		                method: opt,
		        		            });
		        					
//		        					Ext.dispatch({
//		        		                controller: FlyTalk.controllers.dbController,
//		        		                action: opt,
//		        		            });
		        				},
		        			},
		             },
		              this.tweetList];
		
		FlyTalk.views.ColumnView.superclass.initComponent.call(this);
    },
    
    onMenu: function (ind) {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openMenu',
           // post: record,
            index: ind,
        });
    },
    
});